package com.igbeok.miscellaneous.concurrency.thij;

public class Chef2 extends Thread {
	private Restaurant restaurant;
	private WaitPerson2 waitPerson;

	public Chef2(String name, Restaurant restaurant, WaitPerson2 waitPerson) {
		super(name);
		this.restaurant = restaurant;
		this.waitPerson = waitPerson;
	}

	public void run() {
		while (true) {
			// while (restaurant.orders.size() < 100) {
			restaurant.orders.add(new Order2());
			synchronized (waitPerson) {
				if (waitPerson.isWaiting()) {
					System.out.println(this + ": 我准备通知 WaitPerson!");
					waitPerson.notify();
					/*
					 * try { if (restaurant.orders.size() > 10) sleep(3000); }
					 * catch (InterruptedException e) { // TODO Auto-generated
					 * catch block e.printStackTrace(); }
					 */
				} else {
					System.out.println(this + ": WaitPerson 有Order可拿, 不需要通知!");
				}
			}
			// }
		}
	}
}
